<{include file="public/header" /}>
<style>
  .layui-table tbody tr:hover {
      background-color: transparent;
  }
  .layui-table-cell{
    height:auto;
    /*line-height:50;*/
    text-overflow: inherit;
    white-space: normal;
}
</style>
<body>
<div class="layui-container">  
<!-- 顶部搜索 -->
<div class="layui-form">
  <div class="layui-form-item" style="margin-top: 10px;">
    <button class="layui-btn layui-btn-sm" data-type="reload" id="refresh"><i class="layui-icon layui-icon-refresh"></i></button>
  </div>
</div>
<!-- 顶部刷新 -->
<div style="text-align: center;line-height: 50px;">
      <p ><b><h2><{$edata.title}></h2></b></p>
      <p ><h4><{$edata.description}></h4></p>
</div>

<table class="layui-hide" id="shiti" lay-filter="shiti" ></table>


<script type="text/html" id="linetoolbar">
  <!-- <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="banli">办理</a>
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a> -->
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i></a>
</script>   
<script type="text/html" id="questionTpl">
  <b>{{ d.qtitle }}</b> &nbsp;&nbsp;{{ get_question_subject(d.qsubject) }}&nbsp;&nbsp;{{ get_question_type(d.qtype) }}
  <div class="layui-row">
   {{ get_answers(d) }}  {{ get_right_answer(d) }}
  </div>
</script>   
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 --> 
<script>
layui.use(['form','laypage','table','element','jquery'], function(){
  var table = layui.table,laypage=layui.laypage,element=layui.element,$ = layui.$;
var table = layui.table;
  $('#refresh').on('click',function(){
      window.location.reload()
    });

   //数据表格配置
  table.render({
    elem: '#shiti'
    ,url:'<{:url('view_data')}>'+'?qids='+'<{$edata['qids']}>'
    ,toolbar: '#headertoolbar'
    ,defaultToolbar: ['print', 'exports']
    ,text: {none: '<span style="color:red">无考题，请前往【试题管理】添加考题到该考试！</span>' }
    //,skin:'line'
    ,title: '试题表_siku在线考试系统'
    ,cols: [[
      //{type: 'checkbox'}
      //,{field:'qid', title:'ID',width:'6%', sort: true}
      {field:'sort', title:'排序',width:'10%',edit: 'text',sort:true,align:'center'}
      ,{field:'qdata', title:'<center>试题</center>',width:'70%',templet:'#questionTpl'}
      ,{field:'score', title:'<center>分数</center>',width:'10%',edit: 'text',align:'center'}
      // ,{field:'admintype', title:'权限',templet:function(d){return check_admin(d.admintype)}}
      // ,{field:'class', title:'班级', sort: true}
      // ,{field:'grade', title:'年级',sort: true,templet:function(d){return check_grade(d.grade)}}
      // ,{field:'create_time', title:'时间',width:160,sort: true}

      ,{title:'操作', toolbar: '#linetoolbar', width:'10%'}
    ]]
    //,page: true
    ,id: 'hereReload'
  });
  //监听单元格编辑
  table.on('edit(shiti)', function(obj){
    var value = obj.value //得到修改后的值
    ,data = obj.data //得到所在行所有键值
    ,field = obj.field; //得到字段
    //layer.alert(JSON.stringify(value));
    //layer.msg('[ID: '+ data.qid +'] ' + field + ' 字段更改为：'+ value);
    $.post("<{:url('change_sort_score')}>",{qid:data.qid,field:field,value:value},function(data,status){
            //layer.alert(data);
            //layer.alert(JSON.stringify(data));
            //console(data);
            if(data===1){
              layer.msg('修改成功',{time:1000})
            }else{
              layer.alert('系统错误，请刷新重试！',{icon:5});
            }
       })
  });
  
  //监听行工具事件
  table.on('tool(shiti)', function(obj){
    var data = obj.data;
    //console.log(obj);
    //alert(data.tid);
    if(obj.event === 'del'){
      //alert(data.qid);
      layer.confirm('真的删除吗？', function(index){
         $.post("<{:url('del_exam_question')}>"+'?eid='+"<{$edata.eid}>",{id:data.qid},function(data,status){
            //alert(data);
           // alert(JSON.stringify(data));
            //console(data);
            if(data===1){
              layer.close(index);
              obj.del();
              layer.msg('删除成功！',{time:1000})
            }else{
              layer.close(index);
              layer.alert('删除数据错误，请刷新重试！',{icon:5});
            }
       })
      });
    }
  });
  //表格重载
    var active = {
      reload: function(){
        var uname = $('#uname'),grade = $('#grade');
        
        //执行重载
        table.reload('hereReload', {
          page: {
            curr: 1 //重新从第 1 页开始
          }
          ,where: {
            //key: {
              uname: uname.val(),grade:grade.val()
            //}
          }
        });
      }
    };
    
    $('#search').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
});
</script>
</div>  
<div style="height: 150px;background-color: white;"></div>
</body>
</html>
